﻿using System.ComponentModel;
using K9Nano.Application.Authentication;
using K9Nano.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace K9Nano.AspNetCore.Controllers;

/// <summary>
/// 权限接口
/// </summary>
[Route("admin/api/permission")]
[Description("权限接口")]
public class PermissionController(IPermissionAppService service) : ApiControllerBase
{
    /// <summary>
    /// 获取所有权限
    /// </summary>
    /// <returns></returns>
    [HttpGet("all")]
    [Description("获取所有权限")]
    public IEnumerable<Permission> GetAllPermissions() => service.GetAllPermissions();

    /// <summary>
    /// 获取拥有权限的角色列表
    /// </summary>
    /// <param name="permission">权限</param>
    /// <returns></returns>
    [HttpGet("roles/{permission}")]
    [Description("获取拥有权限的角色列表")]
    public Task<IEnumerable<RoleDto>> GetRolesByPermission(string permission)
        => service.GetRolesByPermissionAsync(permission, HttpContext.RequestAborted);
}
